import { Service } from 'egg';
// const fs = require('fs');

/**
 * Test Service
 */
// const { Op } = require("sequelize");
export default class report extends Service {
  public async repotGoods(req) {
    const { user_id, content, category, goods_id, images, reported_person_id } = req;
    let arr: any = [];
    let array = images.split('@');
    for (let i = 0; i < array.length; i++) {
      arr[i] = await this.ctx.helper.writeImage(array[i])
    }
    console.log(reported_person_id);

    if (reported_person_id) {
      let res = await this.ctx.model.Report.create({
        user_id,
        reported_person_id,
        category,
        content,
        imgs: arr.toString()
      })
      if (res) {
        return res
      } else {
        throw new Error()
      }
    } else {
      let res = await this.ctx.model.Report.create({
        user_id,
        goods_id,
        category,
        content,
        imgs: arr.toString()
      })
      if (res) {
        return res
      } else {
        throw new Error()
      }
    }


  }
}